package com.learn.aop.proxy;

import com.learn.aop.proxy.aspect.test.TestBean;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.util.Arrays;

/**
 * https://www.processon.com/view/link/5faa4ccce0b34d7a1aa2a9a5
 *
 * @author gqzdev
 * @date 2021/10/09 17:07
 **/
public class SpringAspectTest {

	public static void main(String[] args) {
		//配置类无需注解直接注册成为配置类Bean
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		Arrays.stream(context.getBeanDefinitionNames()).forEach(System.out::println);
		// TestBean 没有实现接口走的是 CglibAopProxy, 拿到 testBean Cglib代理对象。参见 com.learn.aop.proxy.jdk.Test 里的JDK示例。
		TestBean testBean = context.getBean(TestBean.class);
		// 生成的代理对象中也有 test()方法，在 test()方法里调用了 CglibAopProxy#intercept() 拦截。
		testBean.test();
	}
}
/* Output:
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
appConfig
myAspect
aspectJTest
myAroundAdvise
userService
testBean
org.springframework.aop.config.internalAutoProxyCreator
before1
beforeTest
test
before2
afterTest
*///~